//
//  CLGImageButtonView.m
//  Challenge2
//
//  Created by nqminh on 2/16/12.
//  Copyright (c) 2012 IPSVN. All rights reserved.
//

#import "ImageButtonView.h"

@implementation ImageButtonView

@synthesize actionButton;

- (id)initWithImage:(UIImage *)image
{
	[super initWithImage:image];
	
	if (actionButton == nil)
	{
		actionButton = [UIButton buttonWithType:UIButtonTypeCustom];
		actionButton.frame = CGRectZero;
		[self addSubview:actionButton];
		[self bringSubviewToFront:actionButton];
		[self setUserInteractionEnabled:YES];			
		
		actionButton.backgroundColor = (image == nil ? [UIColor blackColor] : [UIColor clearColor]);
        actionButton.tag = (NSInteger)self;
    }

    return self;
}

- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents
{
    [actionButton addTarget:target action:action forControlEvents:controlEvents];
}

- (void)setFrame:(CGRect)rect
{			
	[super setFrame:rect];
	actionButton.frame = CGRectMake(0, 0, rect.size.width, rect.size.height);
}

@end
